<?php

/** UPDATED
 * This is the model class for table "gn_users".
 *
 * The followings are the available columns in table 'gn_users':
 * @property integer $user_id
 * @property string $password
 * @property string $f_name
 * @property string $l_name
 * @property string $m_initial
 * @property string $email
 * @property string $mobile_no
 * @property string $position
 * @property string $user_type
 * @property integer $accessLevel
 * @property string $dt_created
 */
class Users extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Users the static model class
	 */

	const LEVEL_REGISTERED=1,LEVEL_ADMIN=2;

    static function getAccessLevelList($level=null){
	
	    $levelList=array(
		    self::LEVEL_REGISTERED=>'Viewer',
			self::LEVEL_ADMIN=>'Admin'
		);
		if($level===null)
		    return $levelList;
			
		return $levelList[$level];
	}

	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'gn_users';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			//array('password, f_name, l_name, email, mobile_no, dt_created', 'required'),
			array('password, f_name, l_name, email, mobile_no', 'required'),
			array('accessLevel', 'numerical', 'integerOnly'=>true),
			array('password', 'length', 'max'=>255),
			array('f_name, l_name, m_initial, email, mobile_no, position', 'length', 'max'=>45),
			array('user_type', 'length', 'max'=>7),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('user_id, password, f_name, l_name, m_initial, email, mobile_no, position, user_type, accessLevel, dt_created', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'user_id' => 'User',
			'password' => 'Password',
			'f_name' => 'First Name',
			'l_name' => 'Last Name',
			'm_initial' => 'Middle Name',
			'email' => 'Email',
			'mobile_no' => 'Mobile No',
			'position' => 'Position',
			'user_type' => 'User Type',
			'accessLevel' => 'Access Level',
			'dt_created' => 'Date Created',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('user_id',$this->user_id);
		$criteria->compare('password',$this->password,true);
		$criteria->compare('f_name',$this->f_name,true);
		$criteria->compare('l_name',$this->l_name,true);
		$criteria->compare('m_initial',$this->m_initial,true);
		$criteria->compare('email',$this->email,true);
		$criteria->compare('mobile_no',$this->mobile_no,true);
		$criteria->compare('position',$this->position,true);
		$criteria->compare('user_type',$this->user_type,true);
		$criteria->compare('accessLevel',$this->accessLevel);
		$criteria->compare('dt_created',$this->dt_created,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}